import React, {forwardRef, useRef} from 'react';
import {Modal} from 'antd';
import DataForm from './DataForm';
import {useModel} from '@umijs/max';

const ModalForm: React.FC = forwardRef((props, ref) => {
    //数据模型
    const adminModel = useModel('admin.admin', (model) => ({
        data: model.data,
    }));
    // 表单
    const formRef = useRef();
    return (
        <Modal
            title={adminModel.data.id ? '编辑' : '新建'}
            mask={true}
            maskClosable={false}
            destroyOnClose={true}
            onCancel={() => {
                props.onCancel();
            }}
            visible={props.modalVisible}
            footer={false}
        >
            {props.modalVisible && <DataForm
                ref={formRef}
                onSubmit={async (res) => {
                    props.onSubmit(res);
                }}
            />}
        </Modal>
    );
});

export default ModalForm;
